#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include "pwm_music.h"
#include "driver2/fs4412_pwm.h"
#include "driver1/fs4412_led.h"


int main(int argc, const char *argv[])
{
	

	int fd;
	int data;

	fd = open("/dev/adc", O_RDWR);
	if (fd < 0) {
		perror("open");
		exit(1);
	}

	while(1) {
		read(fd,&data,sizeof(data));
		printf("digital data is : %d:\n",  data );
		printf("analog data is : %0.2fV\n", 1.8 * data / 4096);
		
		if((1.8 * data / 4096)>1){
				int fd1;
				int a = 1;
				fd1 = open("/dev/led", O_RDWR);
				if (fd < 0) {
					perror("open");
					exit(1);
				}
				int i = 0;
				int n = 2;
				int dev_fd;
				int div;
				int pre = 199;
				dev_fd = open("/dev/pwm",O_RDWR | O_NONBLOCK);
				if ( dev_fd == -1 ) {
					perror("open");
					exit(1);
				}
				ioctl(dev_fd,PWM_ON);
				ioctl(fd1,LED_ON,&a);			//请在此处添加第i个灯亮的代码，入口函数int ioctl(int fd,int cmd,char *argp);
				if(++a == 6)
				a = 1;

		}

		if((1.8 * data / 4096)<1){
			    ioctl(dev_fd,PWM_OFF);
				ioctl(fd1,LED_OFF,&a);			//请在此处添加第i个灯亮的代码，入口函数int ioctl(int fd,int cmd,char *argp);
		}

		 
		sleep(1);
	}


	return 0;
}



